package com.hbnu.zhouxunfa;


import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class PictureServer {
    public static void main(String[] args) {
        File file = new File("Websocaket\\serverdir\\001.jpg");
        try {
            ServerSocket ss = new ServerSocket(8080);
            Socket socket = ss.accept();
            InputStream is = socket.getInputStream();
            FileOutputStream fos = new FileOutputStream(file);
            int len;
            System.out.println("图片接收中...");
            while ((len = is.read())!=-1){
                fos.write(len);
            }
            System.out.println("图片接收完毕...");
            //回显数据
            String str = "服务端成功接收";
            OutputStream os = socket.getOutputStream();
            os.write(str.getBytes());

            socket.close();
            ss.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
